
RM=/bin/rm
MKDIR=/bin/mkdir
CP=/bin/cp
TAR=/bin/tar
GZIP=/bin/gzip
MV=/bin/mv
ECHO=/bin/echo
CAT=/bin/cat
CUT=/bin/cut
LN=/bin/ln
SVN=/usr/bin/svn

# RPMDEVSETUPTREE=/usr/bin/rpmdev-setuptree
RPMBUILD=/usr/bin/rpmbuild
RPMLINT=/usr/bin/rpmlint

WORKING=working
BUILD=${HOME}/rpmbuild/BUILD
RPMS=${HOME}/rpmbuild/RPMS
SOURCES=${HOME}/rpmbuild/SOURCES
SPECS=${HOME}/rpmbuild/SPECS
SRPMS=${HOME}/rpmbuild/SRPMS

REVISION=${ECHO} $Rev: 162 $ | ${CUT} --delimiter=' ' --fields=2

all : clean ${WORKING}/helloworld.rpm ${WORKING}/snapshot.rpm ${WORKING}/hourly_snapshot.rpm

working/helloworld.tar :
	${MKDIR} --parents ${WORKING}/files/helloworld-`${REVISION}`
	${TAR} --create --file=$@ --directory=src usr/local/bin/helloworld
	${TAR} --directory=${WORKING}/files/helloworld-`${REVISION}` --extract --file=$@
	${TAR} --create --file=$@ --directory=${WORKING}/files helloworld-`${REVISION}`

working/snapshot.tar :
	${MKDIR} --parents ${WORKING}/files/snapshot-`${REVISION}`
	${TAR} --create --file=$@ --directory=src usr/local/bin/snapshot etc/snapshot.conf
	${TAR} --directory=${WORKING}/files/snapshot-`${REVISION}` --extract --file=$@
	${TAR} --create --file=$@ --directory=${WORKING}/files snapshot-`${REVISION}`

working/hourly_snapshot.tar :
	${MKDIR} --parents ${WORKING}/files/hourly_snapshot-`${REVISION}`
	${TAR} --create --file=$@ --directory=src etc/cron.hourly/hourly_snapshot
	${TAR} --directory=${WORKING}/files/hourly_snapshot-`${REVISION}` --extract --file=$@
	${TAR} --create --file=$@ --directory=${WORKING}/files hourly_snapshot-`${REVISION}`

${SOURCES}/%.tar.gz : ${WORKING}/%.tar
	${MKDIR} --parents ${SOURCES}
	${GZIP} --to-stdout -9 $< > $@

${SPECS}/%.spec : %.spec
	${MKDIR} --parents ${SPECS}
	${ECHO} "Version: `${REVISION}`" > $@
	${CAT} $< >> $@

${WORKING}/%.rpm : ${SPECS}/%.spec ${SOURCES}/%.tar.gz
	${MKDIR} --parents ${BUILD} ${RPMS} ${SRPMS}
	${RPMBUILD} -v -bb --clean $<

clean :
	${RM} --recursive --force ${BUILD} ${RPMS} ${SOURCES} ${SPECS} ${SRPMS} temp ${WORKING} *~
	${SVN} commit -m ${MESSAGE}